/* eslint-disable */
import React, { lazy, Suspense } from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom';

const Main = lazy(() => import('../pages/main'));
const Home = lazy(() => import('../pages/home'));
const Check = lazy(() => import('../pages/class/check'));
const Patriarch = lazy(() => import('../pages/class/patriarch'));
const Publish = lazy(() => import('../pages/task/publish'));
const Test = lazy(() => import('../pages/task/test'));
const View_Inf = lazy(() => import('../pages/warn/view_inf'));
const TeacherMessage = lazy(() => import('../pages/warn/TeacherMessage'));
const StudentProfile = lazy(() => import('../pages/class/StudentProfile'));
const Login = lazy(() => import('../pages/AuthPage/AuthPage'));
const Register = lazy(() => import('../pages/auth/register'));
const User = lazy(() => import('../pages/user'));
const ArticleDetails = lazy(() => import('../pages/home/ArticleDetail'));
const NotFound = lazy(() => import('../pages/nofound/NotFound'));
const TeacherPost = lazy(() => import('../pages/task/teacherpost'));
const SearchResults = lazy(() => import('../pages/SearchResults'));


const router = [
    {
      path: "/",
      element: <Navigate to="/login" replace />, // 默认重定向到登录页面
    },
    {
      path: "/",
      element: (
        <Suspense fallback={<div>Loading...</div>}>
          <Main />
        </Suspense>
      ),
      children: [
        {
          path: 'home',
          element: (
            <Suspense fallback={<div>Loading...</div>}>
              <Home />
            </Suspense>
          )
        },
        {
          path: 'article/:id', // 将 ArticleDetails 的路由配置移到顶层
          element: (
            <Suspense fallback={<div>Loading...</div>}>
              <ArticleDetails />
            </Suspense>
          )
        },
        {
          path: 'class',
          children: [
            {
              path: 'check',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <Check />
                </Suspense>
              )
            },
            {
              path: 'patriarch',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <Patriarch />
                </Suspense>
              )
            }
          ]
        },
        {
          path: 'task',
          children: [
            {
              path: 'test',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <Test />
                </Suspense>
              )
            },
            {
              path: 'publish',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <Publish />
                </Suspense>
              )
            },
            {
              path: 'teacherpost',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <TeacherPost />
                </Suspense>
              )
            }
          ]
        },
        {
          path: 'warn',
          children: [
            {
              path: 'view_inf',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <View_Inf />
                </Suspense>
              )
            },
            {
              path: 'teachermessage',
              element: (
                <Suspense fallback={<div>Loading...</div>}>
                  <TeacherMessage />
                </Suspense>
              )
            }
          ]
        },
        {
          path: 'user',
          element: (
            <Suspense fallback={<div>Loading...</div>}>
              <User />
            </Suspense>
          )
        },
        {
          path: '*', // 404 页面
          element: (
            <Suspense fallback={<div>Loading...</div>}>
              <NotFound />
            </Suspense>
          )
        }
      ]
    },
    {
      path: '/login',
      element: (
        <Suspense fallback={<div>Loading...</div>}>
          <Login />
        </Suspense>
      )
    },
    {
      path: '/register',
      element: (
        <Suspense fallback={<div>Loading...</div>}>
          <Register />
        </Suspense>
      )
    },
    {
      path: '/notfound',
      element: (
        <Suspense fallback={<div>Loading...</div>}>
          <NotFound />
        </Suspense>
      )
    },
    {
      path: '/student-profile/:studentId', // 将 StudentProfile 移到顶层
      element: (
        <Suspense fallback={<div>Loading...</div>}>
          <StudentProfile />
        </Suspense>
      )
    },
    {
      path: '/search-results', // 添加新的路由
      element: (
        <Suspense fallback={<div>Loading...</div>}>
          <SearchResults />
        </Suspense>
      )
    }
  ];

export default createBrowserRouter(router);